<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录</title>
<link rel="stylesheet" href="layui/css/layui.css">
<script src="layui/layui.js"></script>
</head>
<body>
	<script type="text/javascript">
	layui.use(['layer', 'form','jquery'], function(){
		  var layer = layui.layer;//声明对话框组件
		  var form = layui.form;//声明表单组件
		  var $=layui.jquery;//声明jquery组件
		  
		  layer.open({//定义登录的对话框浮层
			  content: $('#login-dialog').html(),
			  title:'顾客登录',
			  type: 1,
			  closeBtn:0
			});
		  //登录提交表单
		  form.on('submit(login-submit)',function(data){
			  //console.log(data.elem)//被执行事件的元素DOM对象，一般为button对象
			  //console.log(data.form)//被执行提交的form对象，一般在存在form标签时才会返回
			  console.log(data.field)//当前容器的全部表单字段，名值对形式:{name,value}
			  $.post('buyer/login',data.field,function(flag){
				  console.log(flag);
				  switch(flag){
				  	case "0"://登录成功
			        	window.location.href="index.jsp";
			        	break;
			        case "-1"://用户名输入不正确
			        	layer.msg('用户名称输入错误',{icon:5});
			        	break;
			        case "-2"://密码输入不正确
			        	layer.msg('密码输入错误',{icon:5});
			        	break;
			        default:
			        	break;
				  }
			  })
			  return false;//阻止表单跳转。如果需要跳转，去掉本段
		  });
		});
	
	</script>

	<script type="text/html" id="login-dialog">
	<form class="layui-form" method="post">
		<div class="layui-form-item">
			<label class="layui-form-label">用户名称</label>
			<div class="layui-input-inline">
				<input type="text" name="username" required lay-verify="required"
					placeholder="请输入用户名" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">用户密码</label>
			<div class="layui-input-inline">
				<input type="password" name="password" required
					lay-verify="required" placeholder="请输入密码" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="login-submit">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
<a href="adminLogin.jsp" class="layui-btn" id="login-type">管理员登录</a>
<a href="register.jsp" class="layui-btn" id="login-type">顾客注册</a>
	</script>



</body>
</html>